<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Vue源码 | 不眠</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/blog/favicon.ico">
    <meta name="description" content="生活不仅需要氧气，更需要勇气">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.a6f4041f.css" as="style"><link rel="preload" href="/blog/assets/js/app.bd1ef45e.js" as="script"><link rel="preload" href="/blog/assets/js/3.ba154db2.js" as="script"><link rel="preload" href="/blog/assets/js/1.1f0d1f23.js" as="script"><link rel="preload" href="/blog/assets/js/29.67ba4742.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.707cbfdf.js"><link rel="prefetch" href="/blog/assets/js/11.72f1afb7.js"><link rel="prefetch" href="/blog/assets/js/12.2f9bf96e.js"><link rel="prefetch" href="/blog/assets/js/13.05b7b31a.js"><link rel="prefetch" href="/blog/assets/js/14.44f18cf0.js"><link rel="prefetch" href="/blog/assets/js/15.6aafcdf2.js"><link rel="prefetch" href="/blog/assets/js/16.d4a57fd2.js"><link rel="prefetch" href="/blog/assets/js/17.067fa92a.js"><link rel="prefetch" href="/blog/assets/js/18.21af6bf6.js"><link rel="prefetch" href="/blog/assets/js/19.ad8e54ec.js"><link rel="prefetch" href="/blog/assets/js/20.50434d17.js"><link rel="prefetch" href="/blog/assets/js/21.95e1d5d1.js"><link rel="prefetch" href="/blog/assets/js/22.5bbb89a4.js"><link rel="prefetch" href="/blog/assets/js/23.49d7a9a4.js"><link rel="prefetch" href="/blog/assets/js/24.aaae9157.js"><link rel="prefetch" href="/blog/assets/js/25.889add58.js"><link rel="prefetch" href="/blog/assets/js/26.4b48b065.js"><link rel="prefetch" href="/blog/assets/js/27.b06fa976.js"><link rel="prefetch" href="/blog/assets/js/28.f78d3b25.js"><link rel="prefetch" href="/blog/assets/js/30.1158f56f.js"><link rel="prefetch" href="/blog/assets/js/4.c0f4c928.js"><link rel="prefetch" href="/blog/assets/js/5.a69dfd84.js"><link rel="prefetch" href="/blog/assets/js/6.2d4b5bad.js"><link rel="prefetch" href="/blog/assets/js/7.728ad095.js"><link rel="prefetch" href="/blog/assets/js/8.17b33111.js"><link rel="prefetch" href="/blog/assets/js/9.c1e3802f.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.a6f4041f.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-999d3bb4><div data-v-999d3bb4><div id="loader-wrapper" class="loading-wrapper" data-v-2c578df8 data-v-999d3bb4 data-v-999d3bb4><div class="loader-main" data-v-2c578df8><div data-v-2c578df8></div><div data-v-2c578df8></div><div data-v-2c578df8></div><div data-v-2c578df8></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-067bd032 data-v-999d3bb4 data-v-999d3bb4><h3 class="title" data-v-067bd032 data-v-067bd032>不眠</h3> <p class="description" data-v-067bd032 data-v-067bd032>生活不仅需要氧气，更需要勇气</p> <label id="box" class="inputBox" data-v-067bd032 data-v-067bd032><input type="password" value="" data-v-067bd032> <span data-v-067bd032>Konck! Knock!</span> <button data-v-067bd032>OK</button></label> <div class="footer" data-v-067bd032 data-v-067bd032><span data-v-067bd032><i class="iconfont reco-theme" data-v-067bd032></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-067bd032>vuePress-theme-reco</a></span> <span data-v-067bd032><i class="iconfont reco-copyright" data-v-067bd032></i> <a data-v-067bd032><span data-v-067bd032>william</span>
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-999d3bb4><header class="navbar" data-v-999d3bb4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/1.png" alt="不眠" class="logo"> <span class="site-name">不眠</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      目录
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/AudioAndVideo/" class="nav-link"><i class="undefined"></i>
  AudioAndVideo
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/docs/theme-reco/" class="nav-link router-link-active"><i class="undefined"></i>
  前端工程化
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/yokeney" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-999d3bb4></div> <aside class="sidebar" data-v-999d3bb4><div class="personal-info-wrapper" data-v-e2878dae data-v-999d3bb4><img src="/blog/1.png" alt="author-avatar" class="personal-img" data-v-e2878dae> <h3 class="name" data-v-e2878dae>
    william
  </h3> <div class="num" data-v-e2878dae><div data-v-e2878dae><h3 data-v-e2878dae>19</h3> <h6 data-v-e2878dae>Articles</h6></div> <div data-v-e2878dae><h3 data-v-e2878dae>0</h3> <h6 data-v-e2878dae>Tags</h6></div></div> <ul class="social-links" data-v-e2878dae></ul> <hr data-v-e2878dae></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      目录
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/AudioAndVideo/" class="nav-link"><i class="undefined"></i>
  AudioAndVideo
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/docs/theme-reco/" class="nav-link router-link-active"><i class="undefined"></i>
  前端工程化
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/yokeney" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><a href="/blog/docs/theme-reco/" aria-current="page" class="sidebar-link">前端工程化</a></li><li><a href="/blog/docs/theme-reco/typescript.html" class="sidebar-link">TypeScript</a></li><li><a href="/blog/docs/theme-reco/Promise.html" class="sidebar-link">一篇让你彻底掌握Promise</a></li><li><a href="/blog/docs/theme-reco/vueSource.html" aria-current="page" class="active sidebar-link">Vue源码</a></li><li><a href="/blog/docs/theme-reco/reactAndVue.html" class="sidebar-link">React与Vue比较</a></li><li><a href="/blog/docs/theme-reco/Promiseplus.html" class="sidebar-link">Promise从入门到定义</a></li><li><a href="/blog/docs/theme-reco/webpack.html" class="sidebar-link">Webpack5 性能优化</a></li><li><a href="/blog/docs/theme-reco/nginx.html" class="sidebar-link">Nginx缓存配置及开启gzip压缩</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-067bd032 data-v-999d3bb4><h3 class="title" data-v-067bd032 data-v-067bd032>Vue源码</h3> <!----> <label id="box" class="inputBox" data-v-067bd032 data-v-067bd032><input type="password" value="" data-v-067bd032> <span data-v-067bd032>Konck! Knock!</span> <button data-v-067bd032>OK</button></label> <div class="footer" data-v-067bd032 data-v-067bd032><span data-v-067bd032><i class="iconfont reco-theme" data-v-067bd032></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-067bd032>vuePress-theme-reco</a></span> <span data-v-067bd032><i class="iconfont reco-copyright" data-v-067bd032></i> <a data-v-067bd032><span data-v-067bd032>william</span>
            
          <!---->
          2022
        </a></span></div></div> <div data-v-999d3bb4><main class="page" style="padding-right:0;"><section><div class="page-title"><h1 class="title">Vue源码</h1> <div data-v-10e19382><i class="iconfont reco-account" data-v-10e19382><span data-v-10e19382>william</span></i> <i class="iconfont reco-date" data-v-10e19382><span data-v-10e19382>5/28/2020</span></i> <!----> <!----></div></div> <div class="theme-reco-content content__default"><h2 id="_1-准备"><a href="#_1-准备" class="header-anchor">#</a> 1. 准备</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token number">1.</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>lis<span class="token punctuation">)</span><span class="token operator">:</span> 将伪数组转换为真数组
<span class="token number">2</span><span class="token punctuation">.</span>node<span class="token punctuation">.</span>nodeType<span class="token operator">:</span> 得到节点类型
<span class="token number">3</span><span class="token punctuation">.</span>Object<span class="token punctuation">.</span><span class="token function">defineProperty</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> propertyName<span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token operator">:</span> 给对象添加<span class="token operator">/</span><span class="token function">修改属性</span><span class="token punctuation">(</span>指定描述符<span class="token punctuation">)</span>
	<span class="token literal-property property">configurable</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token operator">/</span><span class="token boolean">false</span>  是否可以重新define
	<span class="token literal-property property">enumerable</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token operator">/</span><span class="token boolean">false</span> <span class="token function">是否可以枚举</span><span class="token punctuation">(</span><span class="token keyword">for</span><span class="token punctuation">.</span><span class="token punctuation">.</span>in <span class="token operator">/</span> <span class="token function">keys</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token literal-property property">value</span><span class="token operator">:</span> 指定初始值
	<span class="token literal-property property">writable</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token operator">/</span><span class="token boolean">false</span> <span class="token function">value是否可以修改存取</span><span class="token punctuation">(</span>访问<span class="token punctuation">)</span>描述符
	<span class="token literal-property property">get</span><span class="token operator">:</span> 函数<span class="token punctuation">,</span> 用来得到当前属性值
	<span class="token literal-property property">set</span><span class="token operator">:</span> 函数<span class="token punctuation">,</span> 用来监视当前属性值的变化
<span class="token number">4</span><span class="token punctuation">.</span>Object<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token operator">:</span> 得到对象自身可枚举的属性名的数组
<span class="token number">5</span><span class="token punctuation">.</span>DocumentFragment<span class="token operator">:</span> <span class="token function">文档碎片</span><span class="token punctuation">(</span>高效批量更新多个节点<span class="token punctuation">)</span>
<span class="token number">6</span><span class="token punctuation">.</span>obj<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>prop<span class="token punctuation">)</span><span class="token operator">:</span> 判断prop是否是obj自身的属性
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_2-数据代理-mvvm-js"><a href="#_2-数据代理-mvvm-js" class="header-anchor">#</a> 2. 数据代理(MVVM.js)</h2> <ol><li>通过一个对象代理对另一个对象中属性的操作(读/写)</li> <li>通过vm对象来代理data对象中所有属性的操作</li> <li>好处: 更方便的操作data中的数据</li> <li>基本实现流程</li></ol> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>    <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span> 通过Object<span class="token punctuation">.</span><span class="token function">defineProperty</span><span class="token punctuation">(</span><span class="token punctuation">)</span>给vm添加与data对象的属性对应的属性描述符
    <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span> 所有添加的属性都包含getter<span class="token operator">/</span>setter
    <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">.</span> 在getter<span class="token operator">/</span>setter内部去操作data中对应的属性数据
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="_3-模板解析-compile-js"><a href="#_3-模板解析-compile-js" class="header-anchor">#</a> 3. 模板解析(compile.js)</h2> <div class="language- extra-class"><pre><code>1.模板解析的关键对象: compile对象
2.模板解析的基本流程:
	1). 将el的所有子节点取出, 添加到一个新建的文档fragment对象中
	2). 对fragment中的所有层次子节点递归进行编译解析处理
    	* 对表达式文本节点进行解析
    	* 对元素节点的指令属性进行解析
        	* 事件指令解析
        	* 一般指令解析
  	3). 将解析后的fragment添加到el中显示
3.解析表达式文本节点: textNode.textContent = value
  	1). 根据正则对象得到匹配出的表达式字符串: 子匹配/RegExp.$1
  	2). 从data中取出表达式对应的属性值
  	3). 将属性值设置为文本节点的textContent
4.事件指令解析: elementNode.addEventListener(事件名, 回调函数.bind(vm))
    v-on:click=&quot;test&quot;
  	1). 从指令名中取出事件名
  	2). 根据指令的值(表达式)从methods中得到对应的事件处理函数对象
  	3). 给当前元素节点绑定指定事件名和回调函数的dom事件监听
  	4). 指令解析完后, 移除此指令属性
5.一般指令解析: elementNode.xxx = value
  	1). 得到指令名和指令值(表达式)
  	2). 从data中根据表达式得到对应的值
  	3). 根据指令名确定需要操作元素节点的什么属性
        * v-text---textContent属性
        * v-html---innerHTML属性
        * v-class--className属性
  	4). 将得到的表达式的值设置到对应的属性上
  	5). 移除元素的指令属性
</code></pre></div><h2 id="_4-数据劫持-数据绑定"><a href="#_4-数据劫持-数据绑定" class="header-anchor">#</a> 4. 数据劫持--&gt;数据绑定</h2> <div class="language- extra-class"><pre><code>1.数据绑定(model==&gt;View):
	1). 一旦更新了data中的某个属性数据, 所有界面上直接使用或间接使用了此属性的节点都会更新(更新)

2.数据劫持
	1). 数据劫持是vue中用来实现数据绑定的一种技术
	2). 基本思想: 通过defineProperty()来监视data中所有属性(任意层次)数据的变化, 一旦变化就去更新界面
3.四个重要对象
	1). Observer
		* 用来对data所有属性数据进行劫持的构造函数
      	* 给data中所有属性重新定义属性描述(get/set)
      	* 为data中的每个属性创建对应的dep对象
    2). Dep(Depend)
      	* data中的每个属性(所有层次)都对应一个dep对象
      	* 创建的时机:
        	* 在初始化define data中各个属性时创建对应的dep对象
        	* 在data中的某个属性值被设置为新的对象时
      	* 对象的结构
	        {
	          id, // 每个dep都有一个唯一的id
	          subs //包含n个对应watcher的数组(subscribes的简写)
	        }
		* subs属性说明
			* 当一个watcher被创建时, 内部会将当前watcher对象添加到对应的dep对象的subs中
			* 当此data属性的值发生改变时, 所有subs中的watcher都会收到更新的通知, 从而最终更新对应的界面
	3). Compile
		* 用来解析模板页面的对象的构造函数(一个实例)
		* 利用compile对象解析模板页面
		* 每解析一个表达式(非事件指令)都会创建一个对应的watcher对象, 并建立watcher与dep的关系
		* complie与watcher关系: 一对多的关系
	4). Watcher
      	* 模板中每个非事件指令或表达式都对应一个watcher对象
      	* 监视当前表达式数据的变化
      	* 创建的时机: 在初始化编译模板时
      	* 对象的组成
	     javascript  {
          vm,  //vm对象
          exp, //对应指令的表达式
          cb, //当表达式所对应的数据发生改变的回调函数
          value, //表达式当前的值
          depIds //表达式中各级属性所对应的dep对象的集合对象
                  //属性名为dep的id, 属性值为dep
		}
		

	5). 总结: dep与watcher的关系: 多对多
		* 一个data中的属性对应对应一个dep, 一个dep中可能包含多个watcher(模板中有几个表达式使用到了属性)
		* 模板中一个非事件表达式对应一个watcher, 一个watcher中可能包含多个dep(表达式中包含了几个data属性)
		* 数据绑定使用到2个核心技术
			* defineProperty()
			* 消息订阅与发布

4.双向数据绑定
	1). 双向数据绑定是建立在单向数据绑定(model==&gt;View)的基础之上的
	2). 双向数据绑定的实现流程:
      	* 在解析v-model指令时, 给当前元素添加input监听
      	* 当input的value发生改变时, 将最新的值赋值给当前表达式所对应的data属性
</code></pre></div><h2 id="_5-总结"><a href="#_5-总结" class="header-anchor">#</a> 5). 总结:</h2> <div class="language- extra-class"><pre><code>	1. dep与watcher的关系: 多对多
	 
	2. 一个data中的属性对应对应一个dep, 一个dep中可能包含多个watcher(模板中有几个表达式使用到了属性)

	3. 模板中一个非事件表达式对应一个watcher, 一个watcher中可能包含多个dep(表达式中包含了几个data属性)

	4. 数据绑定使用到2个核心技术
		**defineProperty()**
		**消息订阅与发布**
</code></pre></div><h2 id="_6-双向数据绑定"><a href="#_6-双向数据绑定" class="header-anchor">#</a> 6.双向数据绑定</h2> <div class="language- extra-class"><pre><code>1. 双向数据绑定是建立在单向数据绑定(model==&gt;View)的基础之上的
2. 双向数据绑定的实现流程:
 * 在解析v-model指令时, 给当前元素添加input监听
 * 当input的value发生改变时, 将最新的值赋值给当前表达式所对应的data属性
</code></pre></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">3/24/2022, 1:43:43 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/blog/docs/theme-reco/Promise.html" class="prev">
            一篇让你彻底掌握Promise
          </a></span> <span class="next"><a href="/blog/docs/theme-reco/reactAndVue.html">
            React与Vue比较
          </a></span></p></div> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:0;" data-v-92abcef6></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-a008c6ba data-v-a008c6ba><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-a008c6ba><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-a008c6ba></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-a008c6ba></path></svg></div></div></div>
    <script src="/blog/assets/js/app.bd1ef45e.js" defer></script><script src="/blog/assets/js/3.ba154db2.js" defer></script><script src="/blog/assets/js/1.1f0d1f23.js" defer></script><script src="/blog/assets/js/29.67ba4742.js" defer></script>
  </body>
</html>
